<template>
  <nav class="navbar">
    <div class="left">
      <div class="logo" @click.prevent>图片画廊</div>
      <div class="nav-buttons">
        <router-link to="/" custom v-slot="{ navigate }">
          <button @click="navigate">首页</button>
        </router-link>
        <router-link to="/discover" custom v-slot="{ navigate }">
          <button @click="navigate">发现</button>
        </router-link>
      </div>
    </div>
    <div class="right">
      <button class="login-btn" @click="showLoginModal = true">
        {{ isLoggedIn ? '退出' : '登录' }}
      </button>
    </div>

    <!-- 登录弹窗 -->
    <div v-if="showLoginModal" class="modal-overlay">
      <div class="modal">
        <h2>登录</h2>
        <form @submit.prevent="handleLogin">
          <input type="text" v-model="username" placeholder="用户名" required>
          <input type="password" v-model="password" placeholder="密码" required>
          <div class="modal-buttons">
            <button type="submit">登录</button>
            <button type="button" @click="showLoginModal = false">取消</button>
          </div>
        </form>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const isLoggedIn = ref(false)
const showLoginModal = ref(false)
const username = ref('')
const password = ref('')

const handleLogin = () => {
  isLoggedIn.value = true
  showLoginModal.value = false
  username.value = ''
  password.value = ''
}
</script>

<style scoped>
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--nav-bg-color);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.left {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  user-select: none;
  cursor: default;
  color: var(--text-color);
}

.nav-buttons {
  display: flex;
  gap: 1rem;
}

.nav-buttons button {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  cursor: pointer;
  transition: color 0.3s;
  color: var(--text-color);
}

.nav-buttons button:hover {
  color: var(--primary-color);
}

.right {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.login-btn {
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: 4px;
  background: var(--primary-color);
  color: white;
  cursor: pointer;
  transition: background 0.3s;
}

.login-btn:hover {
  opacity: 0.9;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal {
  background: var(--nav-bg-color);
  padding: 2rem;
  border-radius: 8px;
  width: 300px;
}

.modal h2 {
  color: var(--text-color);
  margin-bottom: 1rem;
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal input {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--nav-bg-color);
  color: var(--text-color);
}

.modal-buttons {
  display: flex;
  gap: 1rem;
}

.modal button {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.modal button[type="submit"] {
  background: var(--primary-color);
  color: white;
}

.modal button[type="button"] {
  background: var(--secondary-color);
  color: white;
}

.nav-buttons button.router-link-active {
  color: var(--primary-color);
}
</style> 